package 字节;

public class 最长回文子串 {
    public String longestPalindrome(String s) {
        int n=s.length();
        String res="";
        for (int i=0;i<n;i++){
            String s1=find(s,i,i+1);
            res=res.length()>s1.length()?res:s1;
            String s2=find(s,i,i);
            res=res.length()>s2.length()?res:s2;
        }
        return res;
    }

    String find(String s,int a,int b){
        while (a>=0&&b<s.length()&&s.charAt(a)==s.charAt(b)){
            a--;
            b++;
        }
        return s.substring(++a,b);
    }
}
